package com.suntianci.stock.face.Impl;

import com.suntianci.stock.face.StockCacheFace;
import com.suntianci.stock.mapper.StockBusinessMapper;
import com.suntianci.stock.pojo.entity.StockBusiness;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName StockCacheFaceImpl
 * @Author 孙天赐
 * @Date 2025/2/27 19:21
 * @Description TODO: 股票缓存层实现类
 */
@Component
public class StockCacheFaceImpl implements StockCacheFace {

    @Autowired
    private StockBusinessMapper stockBusinessMapper;

    /**
     * 缓存股票编码，且编码数据提供所属大盘前缀
     *
     * @return
     */
    @Cacheable(cacheNames = "stock", key = "'stockCodes'")
    @Override
    public List<String> getAllStockCodeWithPredix() {
        //1.获取所有A股股票的编码
        List<String> allCodes = stockBusinessMapper.getAllStockCode();
        //2.添加股票前缀 sh sz
        List<String> prefixCodes = allCodes.stream().map(code -> {
            code = code.startsWith("6") ? "sh" + code : "sz" + code;
            return code;
        }).collect(Collectors.toList());
        return prefixCodes;
    }

}
